package com.atty.dms.dao.mapper;

import com.atty.dms.dao.entity.DormitoryDO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface DormitoryMapper extends BaseMapper<DormitoryDO> {

    /**
     * 更新宿舍的当前入住人数
     */
    @Update("UPDATE dormitories SET current_occupancy = current_occupancy + 1 WHERE dormitory_id = #{dormitoryId}")
    void allocateUserToDormitory(@Param("dormitoryId") Long dormitoryId);


    /**
     * 查询指定宿舍内的所有学生ID（室友ID）
     *
     * @param dormitoryId 宿舍ID
     * @return 学生ID列表
     */
    @Select("SELECT student_id FROM dormitories_students WHERE dormitory_id = #{dormitoryId}")
    List<Long> findRoommateIdsByDormitoryId(@Param("dormitoryId") Long dormitoryId);
}